package com.yan.demo.loopdemo;
/*
    4/1   4/5   4/9
    -4/3  -4/7   -4/11
 */
public class LoopDemo1 {
    public static void main(String[] args) {
        double bit = 0;
        double pi = 0;
        int n = 0;
        while(true){
            n++;
            bit = 4.0 / (2 * n - 1);
            if(n % 2 != 0){
                /*pi = pi + i / j;
                j = j + 4;*/
                pi += bit;
            }else {
                /*pi -= i / k;
                k = k + 4;*/
                pi -= bit;
            }
            if(pi >= 3.1415926 && pi <= 3.1415927){
                System.out.println("当前轮数为:" + n);
                break;
            }
        }
    }
}
